package com.woniu.user.controller.web;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.woniu.user.domain.CustomerCoupon;
import com.woniu.user.service.ICustomerCouponService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 用户优惠券Controller
 *
 * @author yy
 * @date 2023-04-03
 */
@RestController
@RequestMapping("/user/tbcustomercoupon/web")
@Api("用户优惠券管理")
public class CustomerCouponWebController extends BaseController
{

    @Autowired
    private ICustomerCouponService customerCouponService;

    /**
     * 新增用户优惠券
     */
    @PostMapping("insertUserCustomer")
    public Long add(@RequestBody CustomerCoupon customerCoupon)
    {
        customerCouponService.insertCustomerCoupon(customerCoupon);

        return customerCoupon.getId();
    }
    @GetMapping("selectOneByUserIdAndCustomerId")
    public CustomerCoupon selectOneByUserIdAndCustomerId(Long userId,Long couponId)
    {
        CustomerCoupon customerCoupon= customerCouponService.selectOneByUserIdAndCustomerId(userId,couponId);
        return customerCoupon;
    }
    @GetMapping("selectOneById")
    public CustomerCoupon selectOneById(Long id)
    {
        CustomerCoupon customerCoupon= customerCouponService.selectCustomerCouponById(id);
        return customerCoupon;
    }

    @PutMapping("updateCouponStatus")
    public AjaxResult edit(Long id)
    {
        CustomerCoupon customerCoupon = customerCouponService.selectCustomerCouponById(id);
        customerCoupon.setCouponStatus(1l);
        return toAjax(customerCouponService.updateCustomerCoupon(customerCoupon));
    }
}
